<template>
  <div class="detail-container">
    <div class="top-wrapper">
      <div class="org-detail">
        <div class="org-info">
          <div class="i-top">
            <div class="t-left">
              <span class="title">{{detail.userName}}</span>
            </div>
            <div class="t-right">
              <el-tag class="tagItem" size="small" type="success">NO:{{detail.id}}</el-tag>
            </div>
          </div>
          <div class="info-detail label-color">
            <div>所属区域：{{detail.areaName}}</div>
            <div>姓名：{{(detail.name)?detail.name:'--'}}</div>
            <div>联系电话：{{detail.mobile}}</div>
          </div>
          <div class="info-detail label-color">
            <div>最后一次登录时间：{{detail.lastLoginTime}}</div>
          </div>
        </div>
      </div>
    </div>
    <div class="bottom-wrapper">
      <div class="table-title">
        <div class="tit-left">
          管理场所码列表
        </div>
        <div class="tit-right">
          <el-button type="success" size="medium" @click="addCs">添加场所</el-button>
        </div>
      </div>
      <el-table
        size="medium"
        :data="tabItems"
        ref="table"
        style="width: 100%;"
        v-loading="tabLoading"
      >
        <el-table-column label="场所码编号" align="center"
          prop="echoMap.csId.id"
        />
        <el-table-column label="场所名称" align="left"
          prop="echoMap.csId.csName"
        />
        <el-table-column label="场所类型" align="left"
          prop="echoMap.csId.typeSecond"
        />
        <el-table-column label="机构名称" align="left"
          prop="echoMap.csId.orgName"
          min-width="80px"
        />
        <el-table-column label="场所地址" align="left"
          prop="echoMap.csId.fullAddress"
          min-width="100px"
        />
        <el-table-column label="联系人手机号" align="center"
          prop="echoMap.csId.applicantPhone"
        />
        <el-table-column label="申领时间" align="center"
          prop="echoMap.csId.createTime"
          min-width="120px"
        />
        <el-table-column label="操作" align="center" fixed="right">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="deleteItem(scope.row)">取消管理</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <SetCSMForm
      ref="set"
      :dialog-visible="dialog.isVisible"
      @close="detailClose"
      @success="editSuccess"
    />
  </div>
</template>

<script>
import { getUser, selectAdminCsPage, deleteAdminCs } from '@/http/apiUrls.js';
import SetCSMForm from '@/components/csmCom/csmManager/SetCSMForm.vue';

export default {
  name: 'CSMManagerDetail',
  components: { SetCSMForm },
  data() {
    return {
      // 编辑框
      dialog:{
        isVisible: false,
        type: 'add'
      },
      detailId: '',
      detail: {
        id: 0,
        csName: '', // 场所名
        typeSecond: '', // 场所类别
        fullAddress: '',
        orgName: '',
        unifiedCode: '',
        reportCheckNeed: '',
        applicantName: '',
        applicantIdCard: '',
        applicantPhone: ''
      },
      activeName: 'csm',
      detailLoading: true,
      tabLoading: false,
      exportLoading: false,
      tableKey: 0,
      pageItems: 10, // 每页查询条数
      pagination: {
        currentPage: 1, // 当前页
        pageSize: 10, // 每页显示条数
        pageCount: 1, // 总页数
      },
      tabItems: [],
    }
  },
  mounted(){
    const id = this.$route.query.id
    this.detailId = id;

    this.getDetailData(id)
    this.getData(1, this.pageItems, id)
  },
  methods:{
    handleClick(tab, event) {
      console.log(tab, event);
    },
    getDetailData(id){
      let url = getUser+id
      this.$getJson(url).then(res => {
        if(res){
          this.detail = res;
        }
      })
    },
    getData(current , size, id){
      let requestData = {
        adminId: id
      }
      this.tabLoading = true;
      this.$postJson(selectAdminCsPage, requestData).then(res => {
        this.tabLoading = false;
        if(res){
          this.tabItems = res;
        }
      })
    },
    addCs(){
      this.$refs.set.setEditObj(this.detail)
      this.dialog = {
        isVisible: true
      }
    },
    detailClose(){
      this.dialog.isVisible = false;
    },
    editSuccess() {
      this.getData(1, this.pageItems, this.detailId)
    },
    deleteItem(item){
      this.$confirm('是否取消管理此场所码?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deleteSubmit(item)
      });
    },
    deleteSubmit(item){
      const requestData = [item.id]
      this.$postJson(deleteAdminCs, requestData).then(res => {
        if(res){
          this.$message({
            type: 'success',
            message: '取消管理成功!'
          });
          this.getData(1, this.pageItems, this.detailId)
        }
      })
    },
  }
}
</script>
<style>
  .el-tabs__item{
    color: rgb(127, 127, 127);
  }
</style>
<style lang="scss" scoped>
.detail-container{
  margin: 10px;
}
.top-wrapper{
  background: #fff;
  padding: 20px;

  .org-detail{
    display:flex;
    display: -webkit-flex;
  }
}

.org-info{
  flex: 1;
  margin-left: 1rem;
  
  .i-top{
    display: flex;
    display: -webkit-flex;
    justify-content: space-between;

    .title{
      font-weight: 700;
    }
    .tagItem{
      margin-left:1rem;
    }
  }
  .info-detail{
    font-size: 14px;
    display: flex;
    display: -webkit-flex;
    margin-top: 0.4rem;
    div:first-child{
      padding-right: 1rem;
    }
    div:not(:first-child){
      padding: 0 1rem;
      border-left: 1px solid #ced6e0;
    }
  }

  .p-info{
    font-size: 14px;
    display: flex;
    display: -webkit-flex;
    margin-top: 0.8rem;
    font-weight: 600;
    div:first-child{
      padding-right: 1.3rem;
    }
    div:not(:first-child){
      padding: 0 1.3rem;
    }
    i{
      color: #409eff;
      font-size: 18px;
      margin-right: 0.5rem;
    }
  }
}

.bottom-wrapper{
  margin-top: 1rem;
  background-color: #fff;
  padding: 1rem;

  .title{
    font-weight: 900;
    margin: 13px 0;
  }
}

.table-title{
  display: flex;
  display: -webkit-flex;
  align-items: center;
  margin-bottom: 1rem;

  .tit-left{
    font-size: 18px;
    font-weight: 600;
  }

  .tit-right{
    flex: 1;
    text-align: right;
  }
}

.detail-info-wrapper{
  
  .info-title{
    font-size: 14px;
    display: flex;
    display: -webkit-flex;
    align-items: center;

    .title{
      font-size: 16px;
    }

    .tag{
      padding: 0 20px;

      .tagItem{
        margin: 0 10px;
      }
    }

    .time-box{
      flex: 1;
      text-align: right;
    }
  }

  .info-detail{
    padding: 10px 0;
    font-size: 12px;
    display: flex;
    display: -webkit-flex;
    flex-wrap: wrap;
    align-items: center;
    .col-item{
      display: flex;
      padding: 5px 0;
      div:first-child{
        width: 115px;
        text-align: right;
      }
    }

    .long-msg{
      width: 35%;
    }

    .short-msg{
      width: 15%;
    }
  }
}

  

</style>